<template>
    <view>
        <view class="password">
            <view class="oldPassword">
                <text class="password2">原密码</text>
                <input class="uni-input"  password="true"  maxlength="16" placeholder="请输入原密码" @input="bindOldPassword" />
            </view>
            <view class="oldPassword">
                <text class="password2">新密码</text>
                <input class="uni-input" password="true" placeholder="请输入密码" maxlength="16" @input="bindNewPassword">
            </view>
            <view class="oldPassword">
                <text class="password2">确定新密码</text>
                <input class="uni-input" password="true" placeholder="请输入密码" maxlength="16" @input="bindNewsPassword">
            </view>
        </view>
        <button class="uni-button" @tap="changePassword">确定</button>
    </view>
</template>

<script>
import {
    request
} from "../../../comon/js/request.js"
export default {
    data() {
        return {
            useId: "",
            oldPassword: "",
            newPassword: "",
            newsPassword: ""
        }
    },
    methods: {
        //获取原密码
        bindOldPassword(event) {
            this.oldPassword = event.target.value
        },
        //获取新密码
        bindNewPassword(event) {
            this.newPassword = event.target.value
        },
        // 确认新密码
        bindNewsPassword(event) {
            this.newsPassword = event.target.value
        },
        // 获取id信息
        getMsg() {
            request({
                url: "v1/passport/detail",
                method: "GET"
            }).then(res => {
                this.useId = res.data.result.id
                uni.setStorageSync("useMsg", res.data.result)
            })
        },
        // 更改密码
        changePassword() {
            let than = this
            if (than.oldPassword === "" || than.newsPassword === "" || than.newPassword === "") {
                uni.showToast({
                    title: "请输入密码",
                    icon: 'none',
                    duration: 2000
                });
                return
            };
            request({
                url: "v1/passport/password",
                method: "POST",
                data: {
                    id: than.useId,
                    old_password: than.oldPassword,
                    password: than.newPassword,
                    c_password: than.newsPassword
                }
            }).then(res => {
                console.log(res)
                if (res.data.result === "修改成功") {
                    uni.showToast({
                        title: "修改成功",
                        icon: 'none',
                        duration: 2000
                    });
                };
                if (res.data.message === "旧密码错误") {
                    uni.showToast({
                        title: "旧密码错误",
                        icon: 'none',
                        duration: 2000
                    });
                }
                if (res.data.message.c_password[0] === "新确认密码不一致") {
                    uni.showToast({
                        title: "请输入相同密码",
                        icon: 'none',
                        duration: 2000
                    });
                }
            })
        }
    },
    onLoad() {
        this.getMsg()
    }
}
</script>

<style lang="less">
.uni-input {
    width: 650rpx;
    height: 88rpx;
    background: #EFF0F3;
    font-size: 35rpx;
    padding-left: 25rpx;

}

.oldPassword {
    margin-top: 30rpx;
}

.password {
    padding-left: 40rpx;
    padding-right: 40rpx;

    .password2 {
        font-size: 13px;
        color: #353535;
        letter-spacing: 0;
        line-height: 30px;
        padding-bottom: 20rpx;
    }
}

.uni-button {
    margin-top: 120rpx;
    width: 564rpx;
    background: #0c69a4;
    color: white;
}
</style>
